<?php
namespace Index\Controller;
use Think\Controller;
class IndexController extends Controller
{
    public function index()
    {
        header("Location:https://xjt.zczmer.com/Seller/Admin/login");
        $this->display();
        // $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover,{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    }


    public function pay_success()
    {

        $this->display();
    }


    public function cs()
    {
        $a = M('order')->where(['order_amount' => 0, 'add_time' => ['gt', '1709223864'], 'order_status' => ['in', '0,1,2']])->select();
        foreach ($a as $order) {
            $goodsArr = [];
            $orderGoods = $this->getOrderGoods($order['order_id'], $order['store_id']);

            foreach ($orderGoods as $val) {
                $goodsArr[] = $val;
            }

            $result = calculate_price($order['user_id'], $goodsArr, $order['shipping_code'], 0, $order['province'], $order['city'], $order['district'], $order['integral'], 0, [], 0, '线下', 11);
            if ($result['status'] < 0) {
                $this->error($result['msg']);
            }

            //echo json_encode($result);exit;
            //################################修改订单费用
            $orderData['goods_price'] = $result['result']['goods_price']; // 商品总价
            $orderData['shipping_price'] = $result['result']['shipping_price'];//物流费
            $orderData['order_amount'] = $result['result']['order_amount']; // 应付金额
            $orderData['total_amount'] = $result['result']['total_amount']; // 订单总价
            $orderData['yijia_heji'] = $result['result']['yijia_heji_s']; // 订单yijia
            $orderData['kou_price'] = $result['result']['kou_price_s']; // 订单收
            M('order')->where("order_id = " . $order['order_id'])->save($orderData);
        }


    }

    public function getOrderGoods($order_id,$store_id){
        $sql = "SELECT g.goods_name,g.original_img,o.*,TRUNCATE(o.goods_num * o.member_goods_price,3) AS goods_total,TRUNCATE(o.goods_num * TRUNCATE (( o.member_goods_price - (o.member_goods_price*(o.points/100))),3),3) AS goods_kou_total,TRUNCATE(o.member_goods_price - (member_goods_price*(o.points/100)),3) AS goods_kou_price FROM __PREFIX__order_goods o ".
            "LEFT JOIN __PREFIX__goods g ON o.goods_id = g.goods_id WHERE o.order_id = $order_id and o.store_id=".$store_id;
        $res = M()->query($sql);
        foreach ($res as $key =>$vs){
            $goods_kou_total = sanwei($vs['goods_num'] * ($vs['member_goods_price'] - ($vs['member_goods_price'] * $vs['points'] /100)));
            $res[$key]['goods_kou_total']=$goods_kou_total;
        }
        return $res;
    }

}